package com.xiaoke.liantongdemo.widget;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xiaoke.liantongdemo.R;
import com.xiaoke.liantongdemo.bean.Business;
import com.xiaoke.liantongdemo.constants.Constants;
import com.xiaoke.liantongdemo.ui.BusinessDetailActivity;

public class BusinessLayout extends RelativeLayout {
	
	private Context context;
	private Business business;
	
	public BusinessLayout(Context context, Business business){
		super(context);
		this.context = context;
		this.business = business;
		init();
	}
	
	private void init(){
		setLayoutParams(new Gallery.LayoutParams(140, 160));
		final ImageView image = new ImageView(context);
		image.setImageResource(R.drawable.pattern1);
//		image.setOnTouchListener(new OnTouchListener() {
//			
//			public boolean onTouch(View v, MotionEvent event) {
//				if(event.getAction() == MotionEvent.ACTION_DOWN){
//					image.setImageResource(R.drawable.book_hover);
//				}else{
//					image.setImageResource(R.drawable.book);
//				}
//				return false;
//			}
//		});
		image.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
//				Toast.makeText(context, "click " + business.getId(), Toast.LENGTH_LONG).show();
				Intent intent = new Intent(context, BusinessDetailActivity.class);
				intent.putExtra(Constants.PARAM_NAME_BUSINESS_ID, 4001);
				context.startActivity(intent);
				
			}
		});
		LayoutParams imageParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
		addView(image, imageParams);
		TextView name = new TextView(context);
		name.setText(business.getName());
		name.setGravity(Gravity.CENTER);
		name.setTextColor(0xff000000);
		name.setTextSize(18);
		LayoutParams nameParams = new LayoutParams(110, 50);
		nameParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
		nameParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		addView(name, nameParams);
	}

}
